import json

from meiduo.utils.ronglian_sms_sdk.SmsSDK import SmsSDK

accId = '8aaf07087b52c64e34517b62d2ffc104d5'
accToken = 'e81fed4610164350e3b543dfad69462f0e43c'
appId = '8aaf0708732b52c6as4e24423017b62d3011b04dc'


def send_message(tid, mobile, datas):
    sdk = SmsSDK(accId, accToken, appId)
    resp = sdk.sendMessage(tid, mobile, datas)
    return json.loads(resp).get('statusCode')


if __name__ == '__main__':
    # 默认测试模板只有 tid = '1', 其他无效
    tid = '2'
    mobile = '17369243721'
    datas = ('1234', '5分钟')
    res = send_message(tid, mobile, datas)
    print(res)

"""
Sign plaintext:  8aaf07087b52c64e017b62d2ffc104d5e81fed46101640e3bdfad69462f0e43c20210820204005
Authorization plaintext: 8aaf07087b52c64e017b62d2ffc104d5:20210820204005
Request url:  https://app.cloopen.com:8883/2013-12-26/Accounts/8aaf07087b52c64e017b62d2ffc104d5/SMS/TemplateSMS?sig=54644294F77BD0EF6E1E2F0BD49CAA82
Request headers:  {'Content-Type': 'application/json;charset=utf-8', 
                   'Accept': 'application/json', 
                   'Accept-Charset': 'UTF-8', 
                   'Authorization': b'OGFhZjA3MDg3YjUyYzY0ZTAxN2I2MmQyZmZjMTA0ZDU6MjAyMTA4MjAyMDQwMDU='}
Request body:  {"to": "17369243721", 
                "appId": "8aaf07087b52c64e017b62d3011b04dc", 
                "templateId": "1", 
                "datas": ["1234", "5\u5206\u949f"]}
Response body:  {"statusCode":"000000",
                 "templateSMS":{"smsMessageSid":"d713e457b4984dd496ffce0d178f84da",
                                "dateCreated":"20210820204006"}}
"""